package com.fangdd.logtrace.async;

import com.fangdd.logtrace.TraceId;
import com.fangdd.logtrace.TraceIdThreadLocal;
import com.fangdd.logtrace.TraceWith;

import java.util.concurrent.Callable;

/**
 * Created by sulong on 16-9-7.
 */
public class TraceCallable<V> implements Callable<V>{
    private Callable<V> inner;
    private TraceId traceId;

    public TraceCallable(Callable<V> real) {
        traceId = TraceIdThreadLocal.concurrentNext();
        this.inner = real;
    }

    public TraceCallable(Callable<V> real, TraceId traceId) {
        this.traceId = traceId;
        this.inner = real;
    }

    @Override
    public V call() throws Exception {
        return TraceWith.run(traceId, inner);
    }
}
